package com.geektime.hello;

import cn.dev33.satoken.SaTokenManager;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

@EnableAsync
@SpringBootApplication
@RestController
@EnableAspectJAutoProxy
@EnableCaching
@MapperScan("com.geektime.hello.mapper")
public class HelloApplication {

    private final static Logger logger = LoggerFactory.getLogger(HelloApplication.class);

    public static void main(String[] args) {

        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                logger.info("---test---" + i);
            }
        }).start();

        SpringApplication.run(HelloApplication.class, args);
        logger.info("sa-token配置如下：" + SaTokenManager.getConfig());

        //第一种通过xml配置
//        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
//        CD sgtPappers = (CD) ac.getBean("sgtPappers");
//        sgtPappers.play();
//        //第二种通过Java Config配置
//        ApplicationContext ac2 = new AnnotationConfigApplicationContext(CDConfig.class);
//        CD sgtPappers2 = (CD) ac.getBean("sgtPappers");
//        sgtPappers2.play();
    }

//    @RequestMapping(value = "/hello")
//    public String hello() {
//        return "Hello Spring";
//    }

    @Component
    public static class CommandLineRunnerTest implements CommandLineRunner {

        @Override
        public void run(String... args) throws Exception {
            System.out.println("======CommandLineRunner在springboot启动时也会执行");
        }
    }

    @Component
    public static class HikariCPTest implements CommandLineRunner {

        @Autowired
        private DataSource dataSource;

        @Override
        public void run(String... args) throws Exception {
            logger.info("【获得数据源: {}】", dataSource.getClass());
        }
    }
}
